package com.atguigu.srb.core.service.impl;

import com.atguigu.srb.core.pojo.entity.UserLoginRecord;
import com.atguigu.srb.core.mapper.UserLoginRecordMapper;
import com.atguigu.srb.core.service.UserLoginRecordService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 用户登录记录表 服务实现类
 * </p>
 *
 * @author fan
 * @since 2021-11-22
 */
@Service
public class UserLoginRecordServiceImpl extends ServiceImpl<UserLoginRecordMapper, UserLoginRecord> implements UserLoginRecordService {

    @Override
    public List<UserLoginRecord> getLoginRecordById(String mobile) {
        QueryWrapper<UserLoginRecord> userLoginRecordQueryWrapper = new QueryWrapper<>();
        userLoginRecordQueryWrapper.eq("user_id",mobile)
        .last("limit 50");

        List<UserLoginRecord> userLoginRecordList = baseMapper.selectList(userLoginRecordQueryWrapper);
        return userLoginRecordList;
    }

    @Override
    public void setUserLoginRecord(String mobile,String ipRemote) {
      QueryWrapper<UserLoginRecord> userLoginRecordQueryWrapper = new QueryWrapper<>();
//        userLoginRecordQueryWrapper.eq("user_id",mobile);
        UserLoginRecord userLoginRecord = new UserLoginRecord();
        userLoginRecord.setIp(ipRemote);
        userLoginRecord.setUserId(mobile);
        baseMapper.insert(userLoginRecord);

    }
}
